package com.springsource.boot.run;

import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.support.ResourcePropertySource;

import java.io.IOException;

public class Step4 {
    public static void main(String[] args) throws IOException {
        StandardEnvironment env = new StandardEnvironment();
        MutablePropertySources propertySources = env.getPropertySources();
        propertySources.addLast(new ResourcePropertySource("classpath:steps/step4.properties"));

        // 加入了一个特殊的Source（ConfigurationPropertySource），将所有不规范的命名，比如减号分割、下划线分割、小驼峰命名，都转化成减号分割的形式
        ConfigurationPropertySources.attach(env);


        for (PropertySource<?> propertySource : propertySources) {
            System.out.println(propertySource);
        }
        System.out.println(env.getProperty("user.first-name"));
        System.out.println(env.getProperty("user.middle-name"));
        System.out.println(env.getProperty("user.last-name"));
    }
}
